import { createHash } from 'node:crypto'
import { getSha1Signature } from './crypt'

/**
 * 计算加密后的消息体签名
 * @param token 消息校验token
 * @param timestamp 来自请求的时间戳
 * @param nonce 来自请求的随机字符串
 * @param encrypt 密文
 */
export function getMsgSignature(token: string, timestamp: string | number, nonce: string, encrypt: string) {
    const list = [token, String(timestamp), nonce, encrypt]
    list.sort((t1, t2) => t1.localeCompare(t2))
    const baseStr = list.join('')
    return createHash('SHA1').update(baseStr).digest('hex').toLowerCase()
}
